const App = getApp()
Page({
  data: {
    userInfo: {},
		allItems:
				{
				id:0,	
				icon: '../../assets/images/order.png',
				text: '我的订单',
				path: '/pages/order/list/index'
			}, 
		address: 
			{
				id:'address',
				icon: '../../assets/images/address.png',
				text: '我的地址',
				path: '/pages/about/index'
			}, 
			ProductSpecification:{
				id:'ProductSpecification',
				icon: '../../assets/images/product.png',
				text: '产品规格',
				path: 'pages/box/index'
			},
			orderStatus:[
				{
					id:1,
					icon:'../../assets/images/pending-payment.png',
					text:'待付款',
					path:'/pages/',
					message:''
				},
				{
					id:2,
					icon:'../../assets/images/waring-delivery.png',
					text:'待发货',
					path:'/pages/',
					message:''
				},
				{
					id:3,
					icon:'../../assets/images/receiving-goods.png',
					text:'待收货',
					path:'/pages/',
					message:''
				},
				{
					id:4,
					icon:'../../assets/images/already-completed.png',
					text:'已完成',
					path:'/pages/',
					message:''
				},
			]
		
  },
  onLoad: function () {
    this.getUserInfo()
  },
	 onShow() {
       this.getOrdersList()
    },
  getUserInfo() {
    	const userInfo = App.globalData.userInfo
		if (userInfo) {
			this.setData({
				userInfo: userInfo
			})
			return
		}
		App.getUserInfo()
		.then(data => {
			this.setData({
				userInfo: data
			})
		})
    },
		//跳转到订单列表页
	navigateTo:function(e){
		var status_type=e.currentTarget.dataset.type
		wx.navigateTo({
		  url: '../order/status?type='+status_type,
		})
	},
	//跳转到我的地址页面
	navigateToaddRess:function(){
		wx.navigateTo({
		  url: '../user/address/index',
		})
	},

	//获取订单信息条数
	getOrdersList:function(){
		var that=this
		wx.showToast({
			title: '加载中',
			icon: 'loading',
			duration: 20000
		})
		App.HttpService.getOrdersList({
			user_id:wx.getStorageSync('user_id')
		}).then(data=>{
			if(data.meat.code ==0 ){
				wx.hideToast()
				var orderStatus_=that.data.orderStatus
					for(var i=0;i<orderStatus_.length;i++){
						if(orderStatus_[i].id==1){
							if(data.data.none_pay != '0'){
								orderStatus_[i].message=data.data.none_pay
							}else{
								orderStatus_[i].message=''
							}
						}else if(orderStatus_[i].id==2){
							if(data.data.can_pay != '0'){
										orderStatus_[i].message=data.data.can_pay
							}else{
								orderStatus_[i].message=''
							}
						}else if(orderStatus_[i].id==3){
							if(data.data.can_get != '0'){
								orderStatus_[i].message=data.data.can_get
							}else{
								orderStatus_[i].message=''
							}
						}else{
							if(data.data.can_up != '0'){
								orderStatus_[i].message=data.data.can_up
							}else{
								orderStatus_[i].message=''
							}
						}
					}
					that.setData({
							orderStatus:orderStatus_
					})
			}
		})
	},

	//跳转到产品规格页
	navigateToProduct:function(e){
		var to_url=e.currentTarget.dataset.path
		wx.navigateTo({
		  url: '../box/index',
		})
	}
})